﻿using System.Collections.Generic;
using System.Data;

namespace Marmat.Data
{
    public class DataRowHelper
    {
        public string TableName { get; set; }
        public string PrimaryKey { get; set; }
        public Suffix Suffix { get; set; }

        public string GetSaveString(DataTable dt, DataRow dr)
        {
            var Helper = new ViewRowHelper();
            Helper.TableName = this.TableName;
            Helper.Suffix = this.Suffix;
            var PrimaryKey = new ViewRowHelper.Column() { DataColumn = this.PrimaryKey, ViewColumn = this.PrimaryKey };
            Helper.PrimaryKey.Add(PrimaryKey);
            return Helper.GetSaveString(dt, dr);
        }

        public string GetSaveString(DataTable dt, DataRow dr, string[] Columns)
        {
            var Helper = new ViewRowHelper();
            Helper.TableName = this.TableName;
            Helper.Suffix = this.Suffix;
            var PrimaryKey = new ViewRowHelper.Column() { DataColumn = this.PrimaryKey, ViewColumn = this.PrimaryKey };
            Helper.PrimaryKey.Add(PrimaryKey);
            var Items = new List<ViewRowHelper.Column>();
            foreach (string Column in Columns)
            {
                var Item = new ViewRowHelper.Column() { DataColumn = Column, ViewColumn = Column };
                Items.Add(Item);
            }

            return Helper.GetSaveString(dt, dr, Items.ToArray());
        }
    }
}